<?php
	
class Table_Mannequins extends Zend_Db_Table_Abstract
{
    protected $_name    = 'mannequin';
    protected $_primary = 'VIP_NUMERO';
    protected $_sequence = true; //la table a un autoincrément
 	
    
	public function isMannequin($numVip){
		return $this->fetchRow($this->select()
									->where('VIP_NUMERO = ? ', $numVip)
				);
	}
	
	public function getAgencesByNum($numVip){
		$req= $this->select()
									->setIntegrityCheck(false)
									->from(array('a'=>'agence'), 'AGENCE_NOM')
									->join(array('ap'=>'apouragence'),			
									'ap.AGENCE_NUMERO = a.AGENCE_NUMERO',
									array('AGENCE_NUMERO'))
									->join(array('m'=>'mannequin'),
									'ap.VIP_NUMERO = m.VIP_NUMERO')
									->where('m.VIP_NUMERO = ?', $numVip)
									->distinct();
									
		$resu=$this->fetchAll($req);
		return $resu;			
	}
	
	public function getDefilesByNum($numVip){
		$req= $this->select()
									->setIntegrityCheck(false)
									->from(array('d'=>'defile'),
									array('DEFILE_LIEU', 'DEFILE_DATE'))
									->join(array('def'=>'defiledans'),
									'd.DEFILE_NUMERO = def.DEFILE_NUMERO',
									array(""))
									->join(array('m'=>'mannequin'),
									'm.VIP_NUMERO = def.VIP_NUMERO',
									array(""))
									->join(array('c'=>'couturier'),
									'd.VIP_NUMERO = c.VIP_NUMERO',
									array(""))
									->join(array('v'=>'vip'),
									'v.VIP_NUMERO = c.VIP_NUMERO',
									array("VIP_NOM" ,'VIP_NUMERO','VIP_TEXTE','VIP_PRENOM'))
									->where('m.VIP_NUMERO = ?', $numVip)
									->distinct();
		$resu=$this->fetchAll($req);
		return $resu;
	}

	public function addMannequin($numvip, $taille){
		$data = array('VIP_NUMERO'=> $numvip,
					  'MANNEQUIN_TAILLE'=>$taille);
		$this->insert($data);
	}
	
	public function deleteVip($numvip){
		$this->delete('VIP_NUMERO = '.$numvip);
	}
	
	public function updateMannequin($num, $taille){
		$data = array('MANNEQUIN_TAILLE' => $taille);
		$where = $this->getAdapter()->quoteInto('VIP_NUMERO = ?', $num);
		return $this->update($data, $where);
	}
}